--[[
* 护盾 效果同6  只是护盾为0 时,不会移除
*]]
---@class BuffEffect66 : BaseBuffEffect
BuffEffect66 = ClientFight.CreateClass("BuffEffect66", ClientFight.BaseBuffEffect)
local t = BuffEffect66
---@param fight Fight
---@param buff FighterBuff
t.EffectType = 66;
function t:action(fight, buff, ...)
    local trigger = parameters[1];
    local result = parameters[3];
    local skill = parameters[2];
    local skillBean = skillskillskillBean;
    if (skillBean.f_HurtMethod == SkillDamageTypeEnum.HEAL) then
        return IBuffEffect.FAIL;
    end
    if (resultdamage <= 0) then
        return IBuffEffect.FAIL;
    end

    SkillRoleMgr.savePathFile("[" .. fightframe + "][EFFECT]Fighter " .. buff.targetfighterId .. " Buff"
            .. buffmodelId .. " 触发护盾BUFF效果，护盾值：" .. buffpoolcurrent);
    local curr = buffpoolcurrent;
    if (resultdamage >= buffpoolcurrent) then
        result.setDamage(resultdamage - buffpoolcurrent);
        buffpool.setCurrent(0, buff);
        if (resultdamage == 0) then
            result.state = DamageResultTypeEnum.SHIELD;
        end
        local frameInfoCommand = ReportManager.buffToJsonString(fight, buff, 3)
        table.insert(fight.actions, frameInfoCommand);
        FightManager.playActions(frameInfoCommand)
    else
        buffpool.setCurrent(buffpoolcurrent - resultdamage, buff);
        result.setDamage(0);
        result.setState(DamageResultTypeEnum.SHIELD);
        fight.getActions().add(ReportManager.buffToJsonString(fight, buff, 3));
    end

    SkillRoleMgr.savePathFile(
            "[" .. fightframe .. "][DAMAGE]" .. buff.sourcefighterId .. "对"
                    .. buff.targetfighterId .. "计算BUFF(" .. buffmodelId .. ")减伤伤害[4]结果,减免后伤害: "
                    .. NumberFormatUtil.formatDamage(resultdamage) .. "  本次护盾抵消:" .. (curr - buffpoolcurrent));

    if (buffpoolcurrent < 0) then
        --护盾 效果同6 , 只是护盾为0 时,不会移除
        --            return IBuffEffect.REMOVE;
    end
    return ClientFight.BaseBuffEffect.action(self, fight, buff, parameters);
end

function t:add(fight, buff)
    local source = buff.source;
    local target = buff.target;
    local baseValue = 0;
    local targetType = 0;
    local attrType = 0;
    local attrRatio = 0;
    local f_BuffEffectValue = buff.buffBeanf_BuffEffectValue;
    if (f_BuffEffectValue ~= nil and table.getn(f_BuffEffectValue) > 0) then
        baseValue = f_BuffEffectValue[1];
        targetType = f_BuffEffectValue[2];
        attrType = f_BuffEffectValue[3];
        attrRatio = f_BuffEffectValue[4];
    else
        baseValue = buffaddParameters[1];
        targetType = buffaddParameters[2];
        attrType = buffaddParameters[3];
        attrRatio = buffaddParameters[4];
    end

    local fighter = targetType == 0 and source or target;
    local value = baseValue;
    if (attrType > 0) then
        value = value + (FighterAttributeManager.getFightAttr(fighter, attrType) * toRatio(attrRatio));
    end
    value = value * buff.getOverlay();
    --buff.setParameter(new int[] { value });
    buffpool.setType(BuffPoolEnum.DEFEAT);
    value = buff.pool.setCurrent(value, buff);
    buff.pool.setMax(value);
    local logv = value;
    SkillRoleMgr.savePathFile("[" .. fightframe .. "][EFFECT]Fighter " .. targetfighterId ..
            " Buff" .. buffmodelId .. " 增加护盾BUFF效果，护盾值：" .. logv);
    return ClientFight.BaseBuffEffect.add(self, fight, buff);
end

t.New()